// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import VueI18n from 'vue-i18n'
import VueClipboard from 'vue-clipboard2'
import Web3 from 'web3'
import ElementUI from 'element-ui';

Vue.use(ElementUI);
Vue.use(VueI18n)
Vue.use(VueClipboard);

const i18n=new VueI18n({
  locale:localStorage.getItem('languageSet')||'zh',   //从localStorage里获取用户中英文选择，没有则默认中文
  messages:{
    'zh':require('./components/language/zh'),
    'en':require('./components/language/en'),
  }
})
Vue.directive('timer', {
  bind(el, binding) {
      el.__time = binding.value;
      el.__timer = setInterval(() => {
          let f = v => (v < 10 ? '0' + v : v),
              o = Math.abs(el.__time + 86400000 * 10000 - Date.now()),
              d = Math.floor(o / 86400000),
              h = Math.floor((o - d * 86400000) / 3600000),
              m = Math.floor((o - d * 86400000 - h * 3600000) / 60000),
              s = Math.floor((o - d * 86400000 - h * 3600000 - m * 60000) / 1000);

          el.innerText = el.__time > 0 ? f(h) + ':' + f(m) + ':' + f(s) : '00:00:00';
      }, 1000);
  },
  update(el, binding) {
      el.__time = binding.value;
  },
  unbind(el, binding) {
      clearInterval(el.__timer);
  }
});

if (typeof web3 !== 'undefined') {
  window.web3 = new Web3(web3.currentProvider);
} else {
  window.web3 = new Web3(new Web3.providers.HttpProvider('https://bsc-dataseed1.binance.org:443'));
}
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  components: { App },
  template: '<App/>'
})
